<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	template="/WEB-INF/template/general.xhtml">
	<ui:define name="title">Generate report</ui:define>
	<ui:define name="navigation">
		<h:form id="nav">
			<p:tabMenu activeIndex="1">
				<p:menuitem value="Home" action="home" icon="ui-icon-home" />
				<p:menuitem value="Generate report" action="generate"
					icon="ui-icon-pencil" />
				<p:menuitem value="Report templates" action="template"
					icon="ui-icon-document" />
			</p:tabMenu>
		</h:form>
	</ui:define>

	<ui:define name="content">
		<h:form id="form">
			<!-- Messages -->
			<p:messages id="messages" showDetail="true" autoUpdate="true"
				closable="true" />
			<!-- Dialogs -->
			<!-- Project selection dialog -->
			<p:dialog id="projectDialog" header="Select project"
				widgetVar="selectProjectName" dynamic="true">

				<p:dataTable autoUpdate="true" id="projectTable" var="projectEntity"
					value="#{reportGenerationBean.projects}" paginator="true"
					rows="#{reportGenerationBean.rowNumber}"
					paginatorTemplate="{PageLinks}"
					selection="#{reportGenerationBean.selectedProject}"
					selectionMode="single" rowKey="#{projectEntity.id}"
					filteredValue="#{reportGenerationBean.filteredProjectList}">

					<p:ajax event="rowSelect" update=":form"
						listener="#{reportGenerationBean.selectNewProject}"
						oncomplete="selectProjectName.hide()" />

					<p:column sortBy="#{projectEntity.projectName}"
						id="projectNameColumn" filterBy="#{projectEntity.projectName}"
						headerText="Name" filterMatchMode="contains">
						<h:outputText value="#{projectEntity.projectName}" />
					</p:column>
					<p:column headerText="Comment">
						<h:outputText value="#{projectEntity.comments}" />
					</p:column>


				</p:dataTable>



			</p:dialog>

			<!-- Scenario selection dialog -->
			<p:dialog id="scenaroDialog" header="Select scenario"
				widgetVar="selectScenarioName" dynamic="true">

				<p:dataTable autoUpdate="true" id="scenarioTable"
					var="scenarioEntity" value="#{reportGenerationBean.scenarios}"
					paginator="true" rows="#{reportGenerationBean.rowNumber}"
					paginatorTemplate="{PageLinks}"
					selection="#{reportGenerationBean.selectedScenario}"
					selectionMode="single" rowKey="#{scenarioEntity.id}"
					filteredValue="#{reportGenerationBean.filteredScenarioList}">

					<p:ajax event="rowSelect"
						listener="#{reportGenerationBean.selectNewScenario}"
						update=":form" oncomplete="selectScenarioName.hide()" />

					<p:column sortBy="#{scenarioEntity.scenarioName}"
						filterBy="#{scenarioEntity.scenarioName}"
						filterMatchMode="contains" id="scenarioNameColumn"
						headerText="Name">
						<h:outputText value="#{scenarioEntity.scenarioName}" />
					</p:column>
					<p:column headerText="Comment">
						<h:outputText value="#{scenarioEntity.comments}" />
					</p:column>


				</p:dataTable>



			</p:dialog>

			<!-- Scenario Type selection dialog -->
			<p:dialog id="scenaroTypeDialog" header="Select scenario type"
				widgetVar="selectScenarioTypeName" dynamic="true">



				<h:outputText
					value='Use "Shift" and "Control" keys for multiselection.' />

				<p:dataTable autoUpdate="true" id="scenarioTypeTable"
					var="scenarioTypeEntity" paginator="true"
					rows="#{reportGenerationBean.rowNumber}"
					paginatorTemplate="{PageLinks}"
					value="#{reportGenerationBean.scenarioTypes}"
					rowKey="#{scenarioTypeEntity.id}"
					selection="#{reportGenerationBean.selectedScenarioType}"
					selectionMode="multiple">




					<p:column headerText="Name">
						<h:outputText value="#{scenarioTypeEntity.scenarioTypeName}" />
					</p:column>

					<p:column headerText="Comment">
						<h:outputText value="#{scenarioTypeEntity.comments}" />
					</p:column>


				</p:dataTable>
				<p:ajax event="close"
					listener="#{reportGenerationBean.selectNewScenarioTypes}"
					update=":form" />

				<p:commandButton value="Submit"
					oncomplete="selectScenarioTypeName.hide()" />

			</p:dialog>

			<!-- BranchId dialog -->

			<p:dialog id="branchDialog" header="Select branch ID"
				widgetVar="selectBranchId" dynamic="true">



				<h:outputText
					value='Use "Shift" and "Control" keys for multiselection.' />

				<p:dataTable autoUpdate="true" id="branchIdTable" var="string"
					paginator="true" rows="#{reportGenerationBean.rowNumber}"
					paginatorTemplate="{PageLinks}"
					value="#{reportGenerationBean.branchId}" rowKey="#{string}"
					selection="#{reportGenerationBean.selectedBranchID}"
					selectionMode="multiple">




					<p:column headerText="Branch ID">
						<h:outputText value="#{string}" />
					</p:column>


				</p:dataTable>
				<p:ajax event="close"
					listener="#{reportGenerationBean.selectNewBranchId}" update=":form" />

				<p:commandButton value="Submit" oncomplete="selectBranchId.hide()" />

			</p:dialog>

			<!-- Build selection dialog -->

			<p:dialog id="buildDialog" header="Select build id"
				widgetVar="selectBuildId" dynamic="true">



				<h:outputText
					value='Use "Shift" and "Control" keys for multiselection.' />

				<p:dataTable autoUpdate="true" id="buildIdTable" var="string"
					paginator="true" rows="#{reportGenerationBean.rowNumber}"
					paginatorTemplate="{PageLinks}"
					value="#{reportGenerationBean.buildId}" rowKey="#{string}"
					selection="#{reportGenerationBean.selectedBuildID}"
					selectionMode="multiple">




					<p:column headerText="Build ID">
						<h:outputText value="#{string}" />
					</p:column>


				</p:dataTable>
				<p:ajax event="close"
					listener="#{reportGenerationBean.selectNewBuildId}" update=":form" />

				<p:commandButton value="Submit" oncomplete="selectBuildId.hide()" />

			</p:dialog>

			<!-- State selection dialog -->

			<p:dialog id="stateDialog" header="Select states"
				widgetVar="selectState" dynamic="true">



				<h:outputText
					value='Use "Shift" and "Control" keys for multiselection.' />

				<p:dataTable autoUpdate="true" id="stateTable" var="string"
					paginator="true" rows="#{reportGenerationBean.rowNumber}"
					paginatorTemplate="{PageLinks}"
					value="#{reportGenerationBean.state}" rowKey="#{string}"
					selection="#{reportGenerationBean.selectedState}"
					selectionMode="multiple">




					<p:column headerText="State">
						<h:outputText value="#{string}" />
					</p:column>


				</p:dataTable>
				<p:ajax event="close"
					listener="#{reportGenerationBean.selectNewState}" update=":form" />

				<p:commandButton value="Submit" oncomplete="selectState.hide()" />

			</p:dialog>
			<!-- Transaction dialog -->
			<p:dialog id="transactionDialog" header="Select transactions"
				widgetVar="selectTransaction" dynamic="true">



				<h:outputText
					value='Use "Shift" and "Control" keys for multiselection.' />

				<p:dataTable autoUpdate="true" id="transactionTable"
					var="transactionEntity" paginator="true"
					rows="#{reportGenerationBean.rowNumber}"
					paginatorTemplate="{PageLinks}"
					value="#{reportGenerationBean.transactions}"
					rowKey="#{transactionEntity.id}"
					selection="#{reportGenerationBean.selectedTransaction}"
					selectionMode="multiple"
					filteredValue="#{reportGenerationBean.filteredTransactions}">




					<p:column headerText="Transaction"
						sortBy="#{transactionEntity.transactionName}"
						filterBy="#{transactionEntity.transactionName}"
						filterMatchMode="contains">
						<h:outputText value="#{transactionEntity.transactionName}" />
					</p:column>


				</p:dataTable>
				<p:ajax event="close"
					listener="#{reportGenerationBean.selectNewTransaction}"
					update=":form" />

				<p:commandButton value="Submit"
					oncomplete="selectTransaction.hide()" />

			</p:dialog>
			<!-- Test summary dialog -->
			<p:dialog id="testSummaryDialog" header="Select test"
				widgetVar="selectTestSummary" dynamic="true">



				<p:dataTable autoUpdate="true" id="testTable"
					var="testSummaryEntity"
					value="#{reportGenerationBean.testSummaries}" paginator="true"
					rows="#{reportGenerationBean.rowNumber}"
					paginatorTemplate="{PageLinks}"
					selection="#{reportGenerationBean.selectedTestSummary}"
					selectionMode="multiple" rowKey="#{testSummaryEntity.id}">

					<p:column headerText="Branch id">
						<h:outputText value="#{testSummaryEntity.branchId}" />
					</p:column>

					<p:column headerText="Build number">
						<h:outputText value="#{testSummaryEntity.buildNumber}" />
					</p:column>

					<p:column headerText="State">
						<h:outputText value="#{testSummaryEntity.state}" />
					</p:column>

					<p:column headerText="Start time">
						<h:outputText value="#{testSummaryEntity.startTime}" />
					</p:column>
					<p:column headerText="Comment">
						<h:outputText value="#{testSummaryEntity.comments}" />
					</p:column>


				</p:dataTable>
				<p:ajax event="close"
					listener="#{reportGenerationBean.selectNewTestSummary}"
					update=":form" />
				<p:commandButton value="Submit"
					oncomplete="selectTestSummary.hide()" />

			</p:dialog>

			<!-- Dialog to save template -->
			<p:dialog id="saveTemplateDialog" header="Enter template name"
				widgetVar="selectTemplate" dynamic="true">

				<h:outputLabel for="name" value="Name:" />
				<p:inputText id="name" value="#{reportGenerationBean.templateName}"
					required="true" label="Name">
					<f:validateLength minimum="2" maximum="30" />
				</p:inputText>
				<p:message for="name" display="icon" />

				<p:commandButton update="form" value="Save"
					actionListener="#{reportGenerationBean.saveReportTemplate}"
					oncomplete="selectTemplate.hide()" />




			</p:dialog>







			<!-- Selection form -->



			<p:panelGrid>
				<f:facet name="header">
					<h:outputText value="Project generation" />
				</f:facet>



				<p:row>
					<p:column>
						<h:outputLabel value="Project name:" />
					</p:column>
					<p:column>
						<h:outputLabel id="projectNameField"
							value="#{reportGenerationBean.reportEntity.project.projectName}" />
					</p:column>
					<p:column>
						<p:commandButton update="projectDialog"
							actionListener="#{reportGenerationBean.getProjectList}"
							oncomplete="selectProjectName.show();" value="Select..." />
					</p:column>
				</p:row>

				<p:row>
					<p:column>
						<h:outputLabel value="Scenario name:" />
					</p:column>
					<p:column>
						<h:outputLabel id="scenearioNameField"
							value="#{reportGenerationBean.reportEntity.scenario.scenarioName}" />
					</p:column>
					<p:column>
						<p:commandButton
							actionListener="#{reportGenerationBean.getScenarioListByProject}"
							value="Select..." oncomplete="selectScenarioName.show()" />
					</p:column>
				</p:row>

				<p:row>
					<p:column>
						<h:outputLabel value="Scenario type:" />
					</p:column>
					<p:column>
						<p:dataList autoUpdate="true" id="scenarioTypeList"
							value="#{reportGenerationBean.reportEntity.scenarioType}"
							var="scenarioTypeEntity" itemType="disc">
							<h:outputText value="#{scenarioTypeEntity.scenarioTypeName}" />
						</p:dataList>
					</p:column>
					<p:column>
						<p:commandButton value="Select..."
							actionListener="#{reportGenerationBean.getScenarioTypeList}"
							oncomplete="selectScenarioTypeName.show()" />
					</p:column>
				</p:row>

				<p:row>
					<p:column>
						<h:outputLabel value="Branch ID:" />
					</p:column>
					<p:column>
						<p:dataList autoUpdate="true" id="branchIdList"
							value="#{reportGenerationBean.reportEntity.branchId}"
							var="string" itemType="disc">
							<p:column>
								<h:outputText value="#{string}" />
							</p:column>
						</p:dataList>
					</p:column>
					<p:column>
						<p:commandButton
							actionListener="#{reportGenerationBean.getBranchIdList}"
							value="Select..." oncomplete="selectBranchId.show()" />
					</p:column>
				</p:row>

				<p:row>
					<p:column>
						<h:outputLabel value="Build:" />
					</p:column>
					<p:column>
						<p:dataList autoUpdate="true" id="buildIdList"
							value="#{reportGenerationBean.reportEntity.build}" var="string"
							itemType="disc">
							<p:column>
								<h:outputText value="#{string}" />
							</p:column>
						</p:dataList>
					</p:column>
					<p:column>
						<p:commandButton
							actionListener="#{reportGenerationBean.getBuildIdList}"
							value="Select..." oncomplete="selectBuildId.show()" />
					</p:column>
				</p:row>

				<p:row>
					<p:column>
						<h:outputLabel value="State:" />
					</p:column>
					<p:column>
						<p:dataList autoUpdate="true" id="stateIdList"
							value="#{reportGenerationBean.reportEntity.state}" var="string"
							itemType="disc">
							<p:column>
								<h:outputText value="#{string}" />
							</p:column>
						</p:dataList>
					</p:column>
					<p:column>
						<p:commandButton
							actionListener="#{reportGenerationBean.getStateList}"
							value="Select..." oncomplete="selectState.show()" />
					</p:column>
				</p:row>

				<p:row>
					<p:column>
						<h:outputLabel value="Interval:" />
					</p:column>
					<p:column>
						<p:calendar value="#{reportGenerationBean.fromDate}" id="fromCal">
							<p:ajax update="form" event="dateSelect"
								listener="#{reportGenerationBean.selectFromDate}" />
						</p:calendar>
					</p:column>
					<p:column>
						<p:calendar value="#{reportGenerationBean.untilDate}"
							id="untilCal">
							<p:ajax update="form" event="dateSelect"
								listener="#{reportGenerationBean.selectUntilDate}" />
						</p:calendar>
					</p:column>
				</p:row>
				<p:row>
					<p:column>
						<h:outputLabel value="Test:" />
					</p:column>
					<p:column>
						<p:dataList autoUpdate="true" id="testSummaryList"
							value="#{reportGenerationBean.reportEntity.testSummaries}"
							var="testSummaryEntity" itemType="disc">
							<p:column>
								<h:outputText value="#{testSummaryEntity.startTime}" />
							</p:column>
						</p:dataList>
					</p:column>
					<p:column>
						<p:commandButton
							actionListener="#{reportGenerationBean.getTestSummaryList}"
							value="Select..." oncomplete="selectTestSummary.show()" />
					</p:column>
				</p:row>
				<p:row>
					<p:column>
						<h:outputLabel value="Report Type:" />
					</p:column>
					<p:column>
						<p:selectOneMenu id="reportType"
							value="#{reportGenerationBean.selectedReportType}">
							<f:selectItem itemLabel="Report type" itemValue="" />
							<f:selectItems value="#{reportGenerationBean.reportType}" />
							<p:ajax
								update=":form:reportSubType :form:selectTransactionButton"
								listener="#{reportGenerationBean.handleReportTypeChange}" />
						</p:selectOneMenu>
					</p:column>
					<p:column>
						<p:selectOneMenu id="reportSubType"
							value="#{reportGenerationBean.selectedReportSubType}">
							<f:selectItem itemLabel="Report subtype" itemValue="" />
							<f:selectItems value="#{reportGenerationBean.reportSubType}" />
						</p:selectOneMenu>
					</p:column>
				</p:row>
				<p:row>
					<p:column>
						<h:outputLabel value="Transactions:" />
					</p:column>
					<p:column>
						<p:dataList autoUpdate="true" id="transactionList"
							value="#{reportGenerationBean.reportEntity.transactions}"
							var="transactionEntity" itemType="disc">
							<p:column>
								<h:outputText value="#{transactionEntity.transactionName}" />
							</p:column>
						</p:dataList>
					</p:column>
					<p:column>
						<p:commandButton id="selectTransactionButton"
							actionListener="#{reportGenerationBean.getTransactionList}"
							value="Select..." oncomplete="selectTransaction.show()" />
					</p:column>
				</p:row>
				<p:row>
					<p:column>
						<h:outputLabel value="File format:" />
					</p:column>
					<p:column></p:column>
					<p:column>
						<p:selectOneMenu id="reportFormat" editable="false"
							value="#{reportGenerationBean.selectedReportFormat}">
							<f:selectItem itemLabel="Report fromat" itemValue="" />
							<f:selectItems value="#{reportGenerationBean.reportFormat}" />

						</p:selectOneMenu>
					</p:column>

				</p:row>
				<p:row>
					<p:column>
						<p:commandButton update="form" value="Generate"
							actionListener="#{reportGenerationBean.generateReport}"
							onclick="PrimeFaces.monitorDownload(start, stop)">
							<p:fileDownload contextDisposition="inline"
								value="#{reportGenerationBean.report}" />
						</p:commandButton>
					</p:column>

					<p:column>
						<p:commandButton update="form" value="Save"
							oncomplete="selectTemplate.show()" />
					</p:column>
					<p:column>
						<p:commandButton update="form" value="Clean"
							actionListener="#{reportGenerationBean.cleanForm}" />
					</p:column>
				</p:row>








			</p:panelGrid>


		</h:form>
	</ui:define>
</ui:composition>